package com.huaxiafinance.management.service.impl;

import com.huaxiafinance.management.dto.request.QueryPOrderDto;
import com.huaxiafinance.management.mapper.PackageOrderMapper;
import com.huaxiafinance.management.model.PackageOrder;
import com.huaxiafinance.management.service.PackageOrderService;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/12/5.
 */
@SuppressWarnings("SpringJavaAutowiringInspection")
@Service
public class PackageOrderServiceImpl implements PackageOrderService{
    private static final Logger logger = Logger.getLogger(PackageOrderServiceImpl.class);
    @Autowired
    private PackageOrderMapper packageOrderMapper;

    @Override
    public MessageResult getPOrderList(QueryPOrderDto dto) {
        logger.info("【接收的请求参数为】======================"+dto);
        MessageResult result = new MessageResult();
        try {
            dto.setPage(dto.getPage() == null ? null:(dto.getPage()-1) * dto.getRows());
            List<PackageOrder> packageOrderList = packageOrderMapper.getOrderList(dto);
            int rows = packageOrderMapper.getOrderListCount(dto);
            result.setData(packageOrderList);
            result.setRows(rows);
            result.setSuccessResult();
            logger.info("【接收到的响应数据为======================】"+result.getAsJSON());
            return result;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        result.setFailureResult();
        return result;
    }

    @Override
    public List<PackageOrder> getAllPackageOrderByUserUuid(String userUuid) {
        return packageOrderMapper.selectAllPackageByUserUuid(userUuid);
    }
}
